import {
    RouteRecordRaw,
    createRouter,
    createWebHashHistory
} from 'vue-router'



const routers: RouteRecordRaw[] = [

    {
        path: "/",
        component: () => {
            return import("@/layout/index.vue")
        },
        children: [
            {
                path: "/analysise",
                component: () => {
                    return import("@/views/analysise.vue")
                },

            },
        ]

    },
    {
        path: "/login",
        name: "login",
        component: () => {
            return import("@/views/login/index.vue")
        },
    }


]

/* 创建路由对象  */
const router = createRouter({
    history: createWebHashHistory(),
    routes: routers
})


router.beforeEach(async (to, from) => {

    const cookie = localStorage.getItem("cookie")
    console.log('object :>> ', cookie);
    if (!cookie) {
        if (to.name !== 'login') {
            return { name: 'login' }
        }
    }


})




export default router
